<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="姓名">
              <a-input placeholder="请输入姓名" v-model="queryParam.userName"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="10" :lg="11" :md="12" :sm="24">
            <a-form-item label="预计离职时间">
              <j-date placeholder="请选择开始日期" class="query-group-cust" v-model="queryParam.planDepartTime_begin"></j-date>
              <span class="query-group-split-cust"></span>
              <j-date placeholder="请选择结束日期" class="query-group-cust" v-model="queryParam.planDepartTime_end"></j-date>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button v-if="!this.showRecord" @click="handleAdd" type="primary" icon="plus">办理离职</a-button>
      <a-button v-if="!this.showRecord" @click="showRecordList(true)" type="text" icon="search">查看入职记录</a-button>
      <a-button v-if="this.showRecord" type="primary" icon="download" @click="handleExportXls('已离职人员导出')">导出</a-button>
      <a-button v-if="this.showRecord" @click="showRecordList(false)" type="text" icon="double-left">返回</a-button>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        :scroll="{x:true}"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        class="j-table-force-nowrap"
        @change="handleTableChange">

        <span slot="planDepartTime" slot-scope="text, record">
          {{text}}
          <a @click="departTime(record)">调整</a>
        </span>

        <span slot="action" slot-scope="text, record">
          <a-popconfirm @confirm="()=>depart(record)" :title="'确定为【'+record.userId_dictText+'】办理离职吗?'">
            <a>确定离职</a>
            </a-popconfirm>

          <a-divider type="vertical" />
          <a-popconfirm :title="'是否将【'+record.userId_dictText+'】从待离职列表中删除'" @confirm="() => handleDelete(record.id)">
            <a>删除</a>
          </a-popconfirm>
        </span>

      </a-table>
    </div>

    <satff-depart-modal ref="modalForm" @ok="modalFormOk"></satff-depart-modal>
  </a-card>
</template>

<script>

  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import SatffDepartModal from './modules/SatffDepartModal'
  import {filterMultiDictText} from '@/components/dict/JDictSelectUtil'
  import {deleteAction, getAction, httpAction} from "@api/manage";
  import dateFormat from "@comp/jeecg/JEasyCron/format-date";

  export default {
    name: 'SatffDepartList',
    mixins:[JeecgListMixin, mixinDevice],
    components: {
      SatffDepartModal
    },
    data () {
      return {
        showRecord:false,
        queryParam: {
          departStatus:0
        },
        description: '离职管理管理页面',
        columns: [],
        // 表头
        columnsRecord: [
          {
            title: '#',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          {
            title:'姓名',
            align:"center",
            dataIndex: 'userId_dictText'
          },
          {
            title:'入职时间',
            align:"center",
            dataIndex: 'workTime',
            customRender:function (text) {
              return !text?"":(text.length>10?text.substr(0,10):text)
            }
          },
          {
            title:'离职时间',
            align:"center",
            dataIndex: 'departTime',
            customRender:function (text) {
              return !text?"":(text.length>10?text.substr(0,10):text)
            }
          },

          {
            title:'离职时部门',
            align:"center",
            dataIndex: 'departmentIds_dictText'
          },
          {
            title:'离职时职位',
            align:"center",
            dataIndex: 'job'
          },
          {
            title:'离职原因',
            align:"center",
            dataIndex: 'departReason'
          },

        ],
        columnsAdd: [
          {
            title: '#',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          {
            title:'姓名',
            align:"center",
            dataIndex: 'userId_dictText'
          },

          {
            title:'部门',
            align:"center",
            dataIndex: 'departmentIds_dictText'
          },
          {
            title:'职位',
            align:"center",
            dataIndex: 'job'
          },
          {
            title:'预计离职日期',
            align:"center",
            dataIndex: 'planDepartTime',
            scopedSlots: { customRender: 'planDepartTime' },
          },
          {
            title:'来源',
            align:"center",
            dataIndex: 'departOrigin_dictText'
          },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            fixed:"right",
            width:147,
            scopedSlots: { customRender: 'action' }
          }
        ],
        url: {
          list: "/satff/satffDepart/list",
          delete: "/satff/satffDepart/delete",
          edit: "/satff/satffDepart/edit",
          deleteBatch: "/satff/satffDepart/deleteBatch",
          exportXlsUrl: "/satff/satffDepart/exportXls",
          importExcelUrl: "satff/satffDepart/importExcel",

        },
        dictOptions:{},
        superFieldList:[],
      }
    },
    created() {
      this.columns = this.columnsAdd;
    this.getSuperFieldList();
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    methods: {
      showRecordList(val) {
        this.showRecord = val;
        if (val) {
          this.columns = this.columnsRecord;
          this.queryParam.departStatus = 1;
        }else{
          this.columns = this.columnsAdd;
          this.queryParam.departStatus = 0;
        }
        this.loadData(1);
      },
      departTime(record) {
        this.$refs.modalForm.departTime(record);
        this.$refs.modalForm.title = "调整预计离职时间";
        this.$refs.modalForm.disableSubmit = false;
      },
      depart(record){
        record.departTime = dateFormat(new Date());
        record.departStatus = 1;
        httpAction(this.url.edit,record,'put').then((res)=>{
          if(res.success){
            this.$message.success("确认离职成功");
            this.$emit('ok');
          }else{
            this.$message.warning(res.message);
          }
          this.loadData(1);
        })
      },

      loadData(arg) {
        if(!this.url.list){
          this.$message.error("请设置url.list属性!")
          return
        }
        //加载数据 若传入参数1则加载第一页的内容
        if (arg === 1) {
          this.ipagination.current = 1;
        }
        var params = this.getQueryParams();//查询条件
        this.loading = true;
        getAction(this.url.list, params).then((res) => {
          if (res.success) {
            //update-begin---author:zhangyafei    Date:20201118  for：适配不分页的数据列表------------
            this.dataSource = res.result.records||res.result;
            if(res.result.total)
            {
              this.ipagination.total = res.result.total;
            }else{
              this.ipagination.total = 0;
            }
            //update-end---author:zhangyafei    Date:20201118  for：适配不分页的数据列表------------
          }else{
            this.$message.warning(res.message)
          }
        }).finally(() => {
          this.loading = false
        })
      },
      initDictConfig(){
      },
      getSuperFieldList(){
        let fieldList=[];
        fieldList.push({type:'string',value:'departOrigin',text:'来源',dictCode:'entry_origin'})
        fieldList.push({type:'Text',value:'departReason',text:'离职原因',dictCode:''})
        fieldList.push({type:'date',value:'departTime',text:'离职日期'})
        fieldList.push({type:'string',value:'departmentIds',text:'离职时部门',dictCode:''})
        fieldList.push({type:'string',value:'job',text:'离职时职位',dictCode:''})
        fieldList.push({type:'date',value:'planDepartTime',text:'预计离职日期'})
        fieldList.push({type:'sel_user',value:'userId',text:'姓名'})
        fieldList.push({type:'date',value:'workTime',text:'入职日期'})
        this.superFieldList = fieldList
      }
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>